﻿using System;
using System.Data;
using System.Web.UI.WebControls;
using Business;
using System.Web.Security;
using Data;
using DataAccess.i2iPortalTableAdapters;
using Models;

public partial class admin_View_Comp : System.Web.UI.Page
{
	Encryption objenc = new Encryption();

	protected void Page_Load(object sender, EventArgs e)
	{
		if(!IsPostBack)
		{																																 

		}
	}
	/// <summary>
	/// Handles the SelectedIndexChanged event of the GridViewReport control.
	/// </summary>
	/// <param name="sender">The source of the event.</param>
	/// <param name="e">The <see cref="System.EventArgs"/> instance containing the event data.</param>
	/// <action>go to View_Report.aspx with component_id and dateRecorded as query string</action>
	protected void GridViewReport_SelectedIndexChanged(object sender, EventArgs e)
	{
		string component_id = FormViewComponent.SelectedValue.ToString();
		string dateRecorded = GridViewReport.SelectedRow.Cells[0].Text;
		Server.Transfer("View_Report.aspx?component_id=" + component_id + "&dateRecorded=" + dateRecorded);
	}
	/// <summary>
	/// Handles the Click event of the CreateReportButton control.
	/// </summary>
	/// <param name="sender">The source of the event.</param>
	/// <param name="e">The <see cref="System.EventArgs"/> instance containing the event data.</param>
	/// <action>go to Create_Report.aspx with component_id as query string</action>
	protected void CreateReportButton_Click(object sender, EventArgs e)
	{
		string component_id = objenc.EncodeUrl(FormViewComponent.SelectedValue.ToString());
		Server.Transfer("Create_Report.aspx?component_id=" + component_id);
	}
	protected void LoginStatus1_LoggingOut(object sender, LoginCancelEventArgs e)
	{

		Session.Contents.Remove("UserDetails");
		Session.Abandon();
		Session.Contents.RemoveAll();
		FormsAuthentication.SignOut();
		Response.Redirect("../Default.aspx");
	}

	protected void UpdateClicked(object sender, EventArgs e)
	{
/*		var dropdownlist = (DropDownList) FormViewComponent.FindControl("dropdownlist_TimeInterval");
		var strUser = dropdownlist.SelectedValue;
		var hiddenBox = (HiddenField) FormViewComponent.FindControl("hidden_interval");
		if (strUser != "3")
		{
			hiddenBox.Value = dropdownlist.SelectedItem.Text;
		}else
		{
			hiddenBox.Value = "";
		}*/
	}

	protected void InsertEmpty(object sender, EventArgs e)
	{
		DropDownList list = (DropDownList)FormViewComponent.FindControl("dropdownlist_TimeInterval");
		ListItem item = new ListItem("", "");
		list.Items.Insert(0, item);
	}

	protected void DropList_PreRender(object sender, EventArgs e)
	{
		DropDownList list = (DropDownList)FormViewComponent.FindControl("dropdownlist_TimeInterval");
		DataRowView drv = (DataRowView) FormViewComponent.DataItem;
		if(FormViewComponent.CurrentMode == FormViewMode.Edit)
		{
			if (drv["Interval_Id"] != null)
			{
				list.SelectedValue = drv["Interval_Id"].ToString();
			}
		}
	}

	protected void Item_OnUpdating(object sender, FormViewUpdateEventArgs e)
	{
		DropDownList list = (DropDownList)FormViewComponent.FindControl("dropdownlist_TimeInterval");
		e.NewValues.Add("Interval_Id",list.SelectedValue);
	}
}
